package com.code.petapp.view

import android.content.Context
import android.util.AttributeSet
import android.view.View
import android.widget.VideoView

class CustomVideoView :VideoView{
    companion object{
        const val TAG = "BirthdayEditText"
    }
    private var mContext: Context
    private var mWidth: Int = 0
    private var mHeight: Int = 0
    constructor(context: Context) : super(context) {
        this.mContext = context
    }

    constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
        this.mContext = context
    }

    constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
            context,
            attrs,
            defStyleAttr
    ) {
        this.mContext = context
    }
    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        if(mWidth == 0 || mHeight == 0){
            val defaultWidth = View.getDefaultSize(0, widthMeasureSpec)
            val defaultHeight = View.getDefaultSize(0, heightMeasureSpec)
            setMeasuredDimension(defaultWidth, defaultHeight)
        }else{
            val defaultWidth = View.getDefaultSize(0, widthMeasureSpec)
            val defaultHeight = View.getDefaultSize(0, heightMeasureSpec)
            var showHeight = ((mHeight.toDouble() / mWidth.toDouble()) * defaultWidth).toInt()
            if(showHeight >= defaultHeight){
                showHeight = defaultHeight
            }
            setMeasuredDimension(defaultWidth, showHeight)
        }
    }
    fun setWH(width: Int, height: Int) {
        mWidth = width
        mHeight = height
    }
}